﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;

public partial class Topics_TopicFiles : BaseTopicPage
{
    public override Role.Roles[] AllowedRoles
    {
        get { return new Role.Roles[] { Role.Roles.Developer, Role.Roles.ContentEditor, Role.Roles.ContentViewer, Role.Roles.ContentPublisher }; }
    }

    public Role.Roles[] EditRoles
    {
        get { return new Role.Roles[] { Role.Roles.Developer, Role.Roles.ContentViewer, Role.Roles.ContentPublisher }; }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                Id = int.Parse(Request.QueryString["Id"]);
            }
            catch
            {
            }
            if (CurrentTopic != null)
            {
                lblTitle.Text = CurrentTopic.Name;
                lblTopicGroup.Text = CurrentTopic.TopicGroup.Name;
                lblNotes.Text = CurrentTopic.TopicGroup.Notes;
            }
        }
    }

    public int Id { get; private set; }

    protected override object SaveViewState()
    {
        ViewState["Id"] = Id;
        return base.SaveViewState();
    }

    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        if (ViewState["Id"] is int)
        {
            Id = (int)ViewState["Id"];
        }
    }

    private Topic currentTopic;
    protected Topic CurrentTopic
    {
        get 
        {
            if (currentTopic == null && Id > 0)
            {
                currentTopic = Topic.GetById(Id);
            }
            return currentTopic;
        }
    }


    protected void dsFiles_SelectData(object sender, Acms.DataControls.SelectEventArgs<TopicFile> e)
    {
        e.SetData(TopicFile.GetAllByTopicId(Id));
    }
}
